function parseURL(url) {
    var a = document.createElement('a');
    a.href = url;
    var info = {
        source: url,
        protocol: a.protocol.replace(':', ''),
        host: a.hostname,
        port: a.port,
        query: a.search,
        params: (function () {
            var ret = {};
            var seg = a.search.replace(/^\?/, '').split('&');
            var len = seg.length, i = 0, s;
            for (; i < len; i++) {
                if (!seg[i]) {
                    continue;
                }
                s = seg[i].split('=');
                ret[s[0]] = s[1];
            }
            return ret;
        })(),
        file: (a.pathname.match(/\/([^\/?#]+)$/i) || [, ''])[1],
        hash: a.hash.replace('#', ''),
        path: a.pathname.replace(/^([^\/])/, '/$1'),
        relative: (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [, ''])[1],
        segments: a.pathname.replace(/^\//, '').split('/')
    };

    info.root = info.protocol + '://' + info.host
			+ (info.port ? (':' + info.port) : '') + '/';

    return info;
}

function rootURL() {
    return window.location.protocol + '//' + window.location.host + '/';
}

function startsWith(src, str) {
    return src.slice(0, str.length) == str;
}

function endsWith(src, str) {
    return src.indexOf(str, src.length - str.length) !== -1;
}

function fileBrowser() {
    var $dlg = $('<div></div>');
    $(document.body).append($dlg);
    $dlg.dialog({
        title: 'Explorer',
        width: 700,
        height: 420,
        closed: false,
        cache: false,
        href: '/explorer.html',
        modal: true,
        resizable: true,
        onClose: function () {
            $dlg.dialog('destroy');
        },
        buttons: [{
            text: 'OK',
            handler: function () {
                var vm = $dlg.find('[data-bind^="explorer"]')[0]['vm'];
                var file = vm.path() + '/' + vm.fileName();
                $dlg.dialog('close');
            }
        }, {
            text: 'Cancel',
            handler: function () {
                $dlg.dialog('close');
            }
        }]
    });
}